{extends file="../global.html"}
{block name=body}



 

      
          <div class="content" >
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form xbs" action="" >
                <div class="layui-form-pane" style="text-align: center;">
                  <div class="layui-form-item" style="display: inline-block;">
                    <!-- <label class="layui-form-label xbs768">日期范围</label>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
                    </div>
                    <div class="layui-input-inline xbs768">
                      <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
                    </div> -->
                    <div class="layui-input-inline">
                      <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                        <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                    </div>
                  </div>
                </div> 
            </form>
            <xblock><button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button><button class="layui-btn" onclick="member_add('添加用户','member-add.html','600','500')"><i class="layui-icon">&#xe608;</i>添加</button><span class="x-right" style="line-height:40px">共有数据：88 条</span></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                     <th>
                          ID
                        </th>
                        <th>
                          导航名称
                        </th>
                        <th>
                            导航地址
                        </th>
                        <th>
                            显示顺序
                        </th>
                    </tr>
                </thead>
                <tbody>
                {foreach $res as $v}
                    <tr class="tr_{$v.navigation_id}">
                        
                        <td class="td"> {$v.navigation_id}</td>
                        <td class="td" id="navigation_name"> {$v.navigation_name}</td>
                        
                       
                        <td class="td" id="navigation_url">{$v.navigation_url}</td>
                        <input type="hidden" class="navigation_sort_{$v.navigation_id}" name="navigation_sort" value="{$v.navigation_sort}">
                        <td class="td-status">
                        {section name=total loop=$num}
                       
                          <span class="layui-btn show-{$v.navigation_id} {if $v.navigation_sort == {$smarty.section.total.index+1}} layui-btn-warm {else} layui-btn-normal{/if}   layui-btn-mini  s_{$smarty.section.total.index+1}" onclick="show({$smarty.section.total.index+1},{$v.navigation_id})">第 {$smarty.section.total.index+1} 位</span>
                        {/section}
                               
                                  
                        
                        </td>
                    </tr>
                   {/foreach}
                </tbody>
            </table>
            <!-- 右侧内容框架，更改从这里结束 -->
            
          </div>
          <script type="text/javascript">

     $(function(){
          
   $('.td').dblclick(function(){
    //获取当前事件作用对象的文本值
    var v=$(this).html();
    //清楚td的文本值
    $(this).empty();
    //创建input
    var input=$('<input type="text" style="width:120px;color:#222">');
    //把创建好的input元素内部插入到td
    $(this).append(input);
    //获取焦点事件
    input.focus();
    //在获取焦点时给input赋值
    input.val(v);
    //使处于选中
    input.select();
    var td=$(this);
    // //绑定失去焦点事件
    input.blur(function(){
    //   //获取当前数据的id
      var id=$(this).parents("tr").find("td:first").html();
    //   //获取当前元素的value值
      var newV=$(this).val();
      var newC=$(this).parents('td').attr('id');

    
     $.ajax({
              type:"post",
              data:{ id:id,newV:newV,newC:newC},
              url:"{url('run/navigation/ajaxEdit')}",
                        success:function(msg){
                            // alert(msg);
                            if(msg==true){
                                alert('修改成功');
                                 
                            }
                         
                         },
                         error:function(){
                                
                        }

                     })
       $(this).parent("td").html(newV);
      $(this).remove();     
                    })

   
    // })
  });
          })

function show(sort,id){
  // alert(state);
  var navigation_sort = $('.navigation_sort_'+id).val();
   $.ajax({
              type:"post",
              data:{ id:id,sort:sort,navigation_sort:navigation_sort},
              url:"{url('run/navigation/ajaxSort')}",
               success:function(msg){
                            if(msg == false){
                              return false;
                            }
                            var span = $('.show-'+msg);
                       
                            for (var i = 0; i <= span.length - 1; i++) {
                              var iii  = $(span[i]);
                              
                                  if(iii.hasClass('layui-btn-warm') === true){
                                      iii.removeClass('layui-btn-warm').addClass('layui-btn-normal'); 
                                  }
                                   if(iii.hasClass('s_'+navigation_sort) === true){
                                    // alert(1);
                                      iii.removeClass('layui-btn-normal').addClass('layui-btn-warm'); 
                                      $('.navigation_sort_'+msg).val(navigation_sort);
                                  }
                            };
                               
                            var spans = $('.show-'+id);
                             for (var i = 0; i <= spans.length - 1; i++) {
                              var iii  = $(spans[i]);
                              // console.log(iii);
                                  if(iii.hasClass('layui-btn-warm') === true){
                                      iii.removeClass('layui-btn-warm').addClass('layui-btn-normal'); 
                                  }
                                   if(iii.hasClass('s_'+sort) === true){
                                      iii.removeClass('layui-btn-normal').addClass('layui-btn-warm'); 
                                      // alert(1);
                                       $('.navigation_sort_'+id).val(sort);
                                  }
                            };
                          }
            })
}
          </script>
        
{/block}
